import hashlib
import os
import datetime
# 文件MD5校验
def md5File(file):
  md5_tool = hashlib.md5()
  with open(file,mode= "rb") as fobj:
      for line in fobj:
          md5_tool.update(line)
      return md5_tool.hexdigest()

# 递归获取目录下的文件(包含子目录)
def getfilename(directory):
    files = []
    for dir_name, sub_dir_list, file_name_list in os.walk(directory):
        if len(file_name_list) > 0:
            for f_name in file_name_list:
                full_file_name = dir_name + "\\" + f_name
                files.append(full_file_name)
    return files
#重命名  3.txt ---> 3_YYYY_MM_DD.txt
def fileRename():
    # 获取当天的日期
    day = datetime.datetime.now().strftime("%Y_%m_%d")

    files = getfilename(r"D:\pythonpro\test2\北京")
    for src_file in files:
        old_file_name = src_file.split(".")
        suffix = src_file.split(".")[1]
        new_file_name = old_file_name + "_" + day + "." + suffix
        os.rename(src_file, new_file_name)

if __name__ == '__main__':
  fileRename()

